<?php
include("./PDO/PdoConnect.php"); //On inclut la connexion à la base de données.
include("./PDO/PdoReunion.php"); //On inclut les fonctions PDO (create / update etc...)
require("./class/Reunion.php"); //On requiere le fichier.$
require("./PDO/PdoCombattant.php");
require("./PDO/PdoLieu.php");
require ("./PDO/PdoCategorie.php");


echo "<form action=\"index.php?page=validerinscription\" method=\"post\" id=\"validate_form\">";
echo "Nom de la réunion : <input id=\"pseudo\" name=\"pseudo\" type=\"text\" class=\"validate[required]\"/>";




echo "Categorie : <select name=\"listecat\">";
$oPDO = new PdoCategorie();
$lesCategories = $oPDO->readAll();
foreach($lesCategories as $uncategorie)
{
    echo "<option value=".$uncategorie['IDCATEGORIE'].">".$uncategorie["NOMCATEGORIE"]."</option>";
}
echo "</select>";
echo"<br>";


$oPDO = new PdoCombattant();
echo "Combattant 1 : <select name=\"listecombattant1\">";
$lescombattants = $oPDO->readAll();
foreach($lescombattants as $uncombattant1)
{
    echo "<option value=".$uncombattant1['IDCOMBATTANT'].">".$uncombattant1["NOMCOMBATTANT"]."</option>";
}
echo "</select>";
echo "Combattant 2 : <select name=\"listecombattant2\">";
$lescombattants2 = $oPDO->readAll();
foreach($lescombattants2 as $uncombattant2)
{
    echo "<option value=".$uncombattant2['IDCOMBATTANT'].">".$uncombattant2["NOMCOMBATTANT"]."</option>";
}
echo "</select>";
echo"<br>";
echo "Lieu : <select name=\"listelieu\">";
$oPDO = new PdoLieu();
$lesLieux = $oPDO->readAll();
foreach($lesLieux as $unlieu)
{
    echo "<option value=".$unlieu['IDLIEU'].">".$unlieu["NOMLIEU"]."</option>";
}
echo "</select>";


   echo "<input type=\"submit\"/>";
echo "</form>";
if (isset($_GET['action']))
{
	$action = $_GET['action'];
}

switch ($action)
{    
	case "ajouter": //On inclut la page pour ajouter une situation.
            include("./page/reunion/ajouter.php");
            break;
        
	case "traitement_ajout": //On inclut la page qui insère la situation en base.
            $reunion = new Reunion();        
            $reunion->setNomReunion($_POST['NOMREUNION']);
            
            $reunion->setIdLieu($_POST['IDLIEU']);
            $oPDO= new PdoReunion();
            $oPDO->create($reunion);
            break;
	case "lister":
            $oPDO = new PdoReunion();
            $lesReunions = $oPDO->readAll(); //ligne est un array contenant toutes les situations
            include("./page/reunion/lister.php");
            break;
            
        case "modifier":
            include("./page/reunion/modifier.php");
            break;
        case "traitement_modif":
            $reunion = new Reunion();
            $reunion->setIdReunion($_POST['IDREUNION']);
            $reunion->setNomReunion($_POST['NOMREUNION']);
           
            $reunion->setIdLieu ($_POST['IDLIEU']);
            
            $pdo = new PdoReunion();
            $pdo->update($reunion);
            break;
        case "supprimer":
            $reunion = new Reunion();
            $reunion->setIdReunion($_GET['IDREUNION']);
            $oPDO = new PdoReunion();
            $oPDO->delete($reunion);
            break;
        
        
            
}